package com.example.exp_4;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Contact extends Fragment {
    LinearLayout contact;
    public String[] names = {"贾奥","于洋","张于凡"};
    public int[] imgs = {R.drawable.ic_baseline_person_24,R.drawable.ic_baseline_person_24,R.drawable.ic_baseline_person_24};

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater,@Nullable ViewGroup container, Bundle saveInstanceState) {
        return inflater.inflate(R.layout.contact, container,false);
    }
    @Override
    public void onViewCreated(View view,@Nullable Bundle onsaveInstanceState) {
        super.onViewCreated(view, onsaveInstanceState);
        contact = view.findViewById(R.id.maincontact);
        List<Map<String,Object>> listItems = new ArrayList<>();
        for (int i= 0;i<names.length;i++) {
            Map<String,Object> listItem = new HashMap<>();
            listItem.put("img",imgs[i]);
            listItem.put("name",names[i]);
            listItems.add(listItem);
        }

        SimpleAdapter simpleAdapter = new SimpleAdapter(getContext(),listItems,R.layout.single_contact,
                new String[]{"img","name"},new int[]{R.id.img__,R.id.name__});
        ListView contacts = view.findViewById(R.id.contacts);
        contacts.setAdapter(simpleAdapter);
    }
}
